package com.example.demo.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.demo.mvp.presenter.BasePresenter
import com.example.demo.mvp.view.MainView

abstract class BaseActivity<V,P : BasePresenter<V>> : AppCompatActivity() , MainView {

    private  var mPresenter:P? = null;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId());
        if(mPresenter == null){
            mPresenter = createPresenter();
        }
        mPresenter!!.bindView(this as V)
        init();
        initData();
    }

    protected abstract fun getLayoutId(): Int

    protected abstract fun init()

    protected abstract fun initData()

    protected abstract  fun  createPresenter() : P

    fun getPresenter() = mPresenter;

    override fun onDestroy() {
        super.onDestroy()
        mPresenter!!.unBindView();
    }
}